using Headspring.Training.Domain.Model;
using Headspring.Training.Domain.Services;
using Headspring.Training.WebUI.Views;

namespace Headspring.Training.WebUI.Presenters
{
	public class TodoPresenter
	{
		private IUserSession _session;
		private IWorkOrderRepository _repository;

		public TodoPresenter(IUserSession session, IWorkOrderRepository repository)
		{
			_session = session;
			_repository = repository;
		}

		public void Execute(IWorkQueueView view)
		{
			Employee currentUser = _session.GetCurrentUser();
			WorkOrderSearchSpecification assignedSpecification = new WorkOrderSearchSpecification();
			assignedSpecification.MatchAssignee(currentUser);
			assignedSpecification.MatchStatus(WorkOrderStatus.Assigned);
			WorkOrder[] assignedWorkOrders = _repository.GetWorkOrders(assignedSpecification);
			view.AssignedWorkOrders = assignedWorkOrders;

			WorkOrderSearchSpecification inProgressSpecification = new WorkOrderSearchSpecification();
			inProgressSpecification.MatchAssignee(currentUser);
			inProgressSpecification.MatchStatus(WorkOrderStatus.InProgress);
			WorkOrder[] workOrdersInProgress = _repository.GetWorkOrders(inProgressSpecification);
			view.WorkOrdersInProgress = workOrdersInProgress;
		}
	}
}